package lab03.test09;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by dell on 2017/12/28.
 */
public class Test09 {
    public static void main(String[] args) {
        List<Book> books = new ArrayList<Book>();
        String path = "F:\\one.txt";
        String path1 = "D:\\two.txt";
        BufferedReader reader = null;
        BufferedWriter writer = null;

        try {
            try {
                reader = new BufferedReader(new FileReader(path));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
            writer = new BufferedWriter(new FileWriter(path1));
            String line = null;

            while ((line = reader.readLine()) != null) {
                Book book = new Book();

                String[] string = line.split("\t");

                book.bookNo = Integer.parseInt(string[0]);
                book.bookName = string[1];
                book.version = string[2];
                book.price = Double.parseDouble(string[3]);
                book.sales = Double.parseDouble(string[4]);

                books.add(book);
            }
            int i = 1;
            for (Book a : books) {
                if (i == 3) {
                    a.price = a.price + 20;
                }
                if (i == 4) {
                    a.price = a.price + 30;
                }
                i++;

                writer.write(a.bookNo + "\t" + a.bookName + "\t" + a.price);
                writer.newLine();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                reader.close();
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
